/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
// 递归：先序遍历的变形，根-右-左，判断如果当前层数已经遍历过了，则不添加到结果中；
func rightSideView(root *TreeNode) (res []int) {
	var traverse func(depth int, node *TreeNode)
	traverse = func(depth int, node *TreeNode) {
		if node == nil {
			return
		}
		if depth > len(res) {
			res = append(res, node.Val)
		}
		traverse(depth+1, node.Right)
		traverse(depth+1, node.Left)
	}

	traverse(1, root)
	return
}